package com.test.flink_source;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class F04FileSource {

    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration();
        configuration.setInteger("rest.port", 8888);
        StreamExecutionEnvironment webUI = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(configuration);

        TextLineInputFormat textLineInputFormat = new TextLineInputFormat();
        Path path = new Path("data/demo");
        FileSource<String> fileSource = FileSource.forRecordStreamFormat(textLineInputFormat, path).build();

        /**
         * 参数一   数据源对象
         * 参数二  水位线  处理事件时间数据时出现乱序数据后的时间推进标准
         * 参数三  名字
         */
        DataStreamSource<String> ds = webUI.fromSource(fileSource, WatermarkStrategy.noWatermarks(), "file source");

        ds.print();

        webUI.execute();
    }
}
